package com.xywy.tangandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.activity.ExpertsArticleAct;
import com.xywy.tangandroid.base.BasicAdapter;
import com.xywy.tangandroid.bean.ExpertArtail;
import com.xywy.tangandroid.util.UIUtil;

public class ExpertShareAdapter extends BasicAdapter<ExpertArtail> {
	private List<ExpertArtail> list;
	private Context context;
	private LayoutInflater inflater;
	private int flag=0;//1是专家分享（用专家回复） 2是专家经验分享
   private  String id;
   
	public ExpertShareAdapter(Context context, List<ExpertArtail> list,int flag ,String id) {
		super(context, list);
		this.context = context;
		this.list = list;
		this.flag=flag;
		this.id=id;
		this.inflater = LayoutInflater.from(context);
		
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		viewHolder holder = null;
		final int i=position;
		if (convertView == null) {
			holder=new viewHolder();
			if(flag==1){
			convertView = inflater.inflate(R.layout.item_expert_share, null);
	        holder.title=(TextView) convertView.findViewById(R.id.expert_share_text);
			holder.address=(TextView) convertView.findViewById(R.id.expert_share_offices);
	        holder.name=(TextView)convertView.findViewById(R.id.doctor_name);
	        holder.img1=(ImageView)convertView.findViewById(R.id.img1);
	        
	        }else{
	        	convertView = inflater.inflate(R.layout.item_expert_exprence_share, null);
	        	holder.expert_share_text=(TextView)convertView.findViewById(R.id.expert_share_text);
	        	
	        	String title=list.get(i).getTitle();
	        	holder.expert_share_text.setText(title);
	        }
			convertView.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Intent intent=new Intent(context, ExpertsArticleAct.class);
					intent.putExtra("id", list.get(i).getId());
					intent.putExtra("cateid", list.get(i).getCategoryid());
					intent.putExtra("document_id", id);
					context.startActivity(intent);
				}
			});
			convertView.setTag(holder);
		
		} else {
			holder = (viewHolder) convertView.getTag();	
		}
		if(flag==1){
			//ר�ҷ���
		}else if(flag==2){
			//ר�Ҿ������
			
		}else{
			UIUtil.showToast(context, "出现异常");
		}
		return convertView;
	}

	public class viewHolder {

		TextView  title;
		
		TextView  address;
        TextView  name;
        ImageView img1;
        
        TextView expert_share_text;//文章标题
	}
}
